<template>
  <!-- 一行六列文字海报-组件属性 -->
  <div class="rowSixColTextAttr">
    <div class="comInfo">
      <div class="item1">
        <div class="label">位置：</div>
        <div class="item">
          <div class="infoCon">
            <div class="con" style="margin-right:20px;">
              <span>x：</span>
              <el-input v-model.number="list.style.x" :disabled="ispreview"></el-input>
            </div>
            <div class="con">
              <span>y：</span>
              <el-input v-model.number="list.style.y" :disabled="ispreview"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div class="item1">
        <div class="label">大小：</div>
        <div class="item">
          <div class="infoCon">
            <div class="con" style="margin-right:20px;">
              <span>w：</span>
              <el-input v-model.number="list.style.w" :disabled="ispreview"></el-input>
            </div>
            <div class="con">
              <span>h：</span>
              <el-input v-model.number="list.style.h" :disabled="ispreview"></el-input>
            </div>
          </div>
          <div id="tipMsg" style="marginLeft:25px;color:red;display:none;">组件最大宽度为1133px</div>
        </div>
      </div>
      <div class="items" v-if="list.value.length > 0">
        <div class="label">海报位：</div>
        <div class="index" v-for="(item, index) in list.value" :key="index">
          <div style="margin-bottom: 15px;">
            <div class="cont" style="margin-top:15px">
              <div class="tit">海报标题：</div>
              <div class="cont_input">
                <el-input v-model.number="item.title" disabled></el-input>
              </div>
            </div>
          </div>
          <div style="margin-bottom: 15px;">
            <div class="cont">
              <div class="tit">光标移动顺序：</div>
              <div class="cont_input">
                <el-input v-model.number="item.index" :disabled="ispreview"></el-input>
              </div>
            </div>
            <div :id="'tipMsg' + index" style="paddingLeft:100px;color:red;display:none;">
              光标移动顺序不能为0，最小从1开始
            </div>
          </div>
          <div style="margin-bottom: 15px;">
            <div class="cont" v-if="!ispreview">
              <div class="tit">示例海报：</div>
              <div @click="addImg(item)" class="cont_input">
                <Upload v-if="item.url == ''" :params="params" @fileList="getImgList"></Upload>
                <Upload v-else :params="params1" @fileList="getImgList"></Upload>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Upload from '@/commont/plugins/uploadImg.vue' //图片上传
export default {
  name: 'rowSixColTextAttr',
  components: { Upload },
  props: {
    comData: {
      type: Object,
      default: () => { }
    },
    ispreview: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      list: this.comData,
      params: {
        type: 'btn',
        btnName: '上传图片',
        url: '/iptv/epg/sichuan/categoryaudit/addPictures',
      },
      params1: {
        type: 'btn',
        url: '/iptv/epg/sichuan/categoryaudit/addPictures',
        btnName: '修改图片',
      },
      index: null,
    }
  },
  watch: {
    'list.style': {
      handler(val) {
        if (val.w > 1133) {
          // this.$message.error('组件宽度最大为1133');
          document.getElementById('tipMsg').style.display = 'block';
          setTimeout(() => {
            document.getElementById('tipMsg').style.display = 'none';
            this.list.style.w = 1133;
            this.list.style.x = 4;
            this.list.style.y = 5;
          }, 2000)
        }
      },
      deep: true,
    },
    'list.value': {
      handler(data) {
        data.forEach((item, idx) => {
          if (item.index == 0) {
            // this.$message.error('位置排序不能为0，至少从1开始');
            let id = 'tipMsg' + idx;
            document.getElementById(id).style.display = 'block';
            setTimeout(() => {
              document.getElementById(id).style.display = 'none';
              item.index = 1;
            }, 2000)
          }
        })
      },
      deep: true,
    }
  },
  methods: {
    addImg(item) {
      const map = new Map(this.list.value.map(i => [i.index, i.index]));
      if (this.list.value.length != map.size) {
        return;
      } else {
        this.index = item.index;
      }
    },
    // 图片信息
    getImgList(data) {
      if (this.index != null) {
        this.list.value.forEach(item => {
          if (item.index == this.index) {
            item.name = data.name;
            item.url = data.fileByteUrl;
          }
        });
      } else {
        this.$message({ message: '轮播为海报排序有重复，请检查！', type: 'warning' });
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.rowSixColTextAttr {
  .comInfo {
    margin: 10px 5px;

    .item1 {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      padding: 10px;
      border-bottom: 1px dashed #dbdbdb;

      &:nth-last-child(1) {
        border: none;
      }

      .label {
        width: 100px;
      }

      .item {
        width: calc(100% - 100px);
      }

      .infoCon {
        display: flex;
        align-items: center;
        flex-direction: row;
        justify-content: flex-start;

        .con {
          display: flex;
          align-items: center;

          span {
            width: 25px;
          }
        }
      }
    }

    .items {
      display: flex;
      flex-direction: column;
      padding: 10px;

      .label {
        width: 80px;
        font-weight: bold;
        font-size: 18px;
      }

      .index {
        margin-top: 10px;
        border-bottom: 1px dashed #cdcdcd;

        .cont {
          margin-bottom: 15px;
          display: flex;
          align-items: center;
          flex-direction: row;
          justify-content: flex-start;

          .tit {
            width: 100px;
          }

          .cont_input {
            width: calc(100% - 100px);
          }
        }
      }
    }
  }
}
</style>